﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SearchService;

public partial class PersionList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if ((this.Request.Params["kw"] != null) && (this.Request.Params["kw"].ToString() != ""))
            {
                Txb_Company.Text = this.Request.Params["kw"].ToString();

                Session["KeyWord"] = Txb_Company.Text;

                bind();


            }
            else if (Session["KeyWord"] != null)
            {
                Txb_Company.Text = Session["KeyWord"].ToString();
                bind();
            }

        }
    }

    protected void Btn_SCompany_Click(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;

        Session["KeyWord"] = Txb_Company.Text;

        bind();

    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        bind();
    }


    private void bind()
    {

        int start = 0;

        int end = 0;

        SearchService.SearchService oService = new SearchService.SearchService();


        object[] obj = oService.SearchCompanyPersonShop(Txb_Company.Text.ToString(), "P", 200);

        AspNetPager1.RecordCount = obj.Length;

        AspNetPager1.CustomInfoHTML = "共：" + AspNetPager1.RecordCount.ToString() + " 条";

        int pageSize = AspNetPager1.PageSize = Int32.Parse(ConfigurationSettings.AppSettings["PageSize"]);
        int pageIndex = AspNetPager1.CurrentPageIndex - 1;

        start = pageSize * pageIndex;
        end = start + pageSize;

        if (end > obj.Length)
        {
            end = obj.Length;
        }

        myRepeater.DataSource = BriefArrayToDataTable(obj, start, end);
        myRepeater.DataBind();



    }


    private DataTable BriefArrayToDataTable(object[] source, int start, int end)
    {
        string dblno = string.Empty;
        int id = 0;
        string fullname = string.Empty;
        string infostate = string.Empty;
        string keyword1 = string.Empty;
        string keyword2 = string.Empty;
        string keyword3 = string.Empty;
        string nickname = string.Empty;


        DataTable dt = new DataTable();
        dt.Columns.Add("memberid");
        dt.Columns.Add("fullname");
        dt.Columns.Add("dblno");
        dt.Columns.Add("infostate");
        dt.Columns.Add("Keyword1");
        dt.Columns.Add("Keyword2");
        dt.Columns.Add("Keyword3");
        dt.Columns.Add("NickName");

        for (int i = start; i < end; i++)
        {
            BriefInfo b = new BriefInfoComparable();
            b = (BriefInfo)source[i];
            dblno = b.DBLNo;
            id = b.MemberID;
            fullname = b.FullName;
            infostate = b.InfoState;
            keyword1 = b.Keyword1;
            keyword2 = b.Keyword2;
            keyword3 = b.Keyword3;
            nickname = b.NickName;

            DataRow dr = dt.NewRow();
            dr["memberid"] = id;
            dr["dblno"] = dblno;
            dr["fullname"] = fullname;
            dr["infostate"] = infostate;

            dr["nickname"] = nickname;
            dr["keyword1"] = keyword1;
            dr["keyword2"] = keyword2;
            dr["keyword3"] = keyword3;

            dt.Rows.Add(dr);
        }

        return dt;
    }

}
